/**
 * CuatroApp.java
 * 
 * Copyright 2008 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Creado el 07/10/2008, 11:23:38 AM
 */
package com.ufps.cuatro;

import java.awt.Component;
import java.util.EventObject;

import javax.swing.JOptionPane;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;


/**
 * <i><b>CuatroApp:</b></i> Clase que ejecuta el contexto de la Aplicación.
 * 
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 07/10/08
 * @see SingleFrameApplication
 */
public class CuatroApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {                    
        CuatroView obj = new CuatroView(this);      
        addExitListener(new ConfirmExit());
        show(obj);
    }   
    
    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     * @param root @DefinicionParametro
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of CuatroApp @DefinicionReturn
     */
    public static CuatroApp getApplication() {
        try{
            CuatroApp objApp = Application.getInstance(CuatroApp.class);
            return objApp;                        
        }catch(java.lang.IllegalStateException ex){
            System.out.println("Error de Inicialización de Contexto: CuatrApp.class.\n" + ex.getMessage());
        }
        return null;
    }   

    /**
     * Main method launching the application.
     * @param args @DefinicionParametro
     */
    public static void main(String[] args) {
        launch(CuatroApp.class, args);
    }
    
    private class ConfirmExit implements ExitListener {
        public boolean canExit(EventObject e) {
            Object source = (e != null) ? e.getSource() : null;
            Component owner = (source instanceof Component) ? (Component)source : null;
            int option = JOptionPane.showConfirmDialog(owner, "Desea Finalizar la Aplicación?");
            return option == JOptionPane.YES_OPTION;
        }
        public void willExit(EventObject e) {} 
    }
}